package com.test.config;

import com.test.bean.Person;
import org.springframework.context.annotation.*;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/11/27 13:39
 * <p>
 * 配置类=配置文件
 * @Configuration 告诉spring这是一个配置类
 * @ComponentScan value:指定要扫描的包
 * excludeFilters = []，指定扫描的时候按照什么规则排除哪些组件
 * excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value = {Controller.class, Service.class})}
 * includeFilters = [], 指定扫描的时候按照什么规则包含哪些组件
 * includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value = {Controller.class})}
 * @ComponentScans可以包含多个componentScan规则 常用的扫描规则：
 * 1.*FilterType.ANNOTATION：按照注解的方式
 * 2.*FilterType.ASSIGNALBLE_TYPE：按照指定的类型
 * 3.FilterType.ASPECTJ:使用aspectj表达式
 * 4.FilterType.REGEX：使用正则表达式
 * 5.FilterType.CUSTOM:使用自定义规则
 */
@Configuration
@ComponentScans(value = {
        @ComponentScan(value = "com.test.bean", useDefaultFilters = false, includeFilters = {
//                @ComponentScan.Filter(type = FilterType.ANNOTATION, value = {Controller.class}),
////                @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {BookService.class}),
                @ComponentScan.Filter(type = FilterType.CUSTOM, classes = {MyTypeFilter.class})
        })
})
public class MainConfig {

    /**
     * 容器中注册一个Bean，类型为返回值的类型，id默认是用方法名作为id
     *
     * @return
     */
    @Bean("person")
    public Person person() {
        return new Person("lisi", 21);
    }
}
